<?php

function print_featured() {
	require("config.php");
	$dynamicList = "";
	$sql = mysql_query("SELECT * FROM products WHERE is_featured='1' LIMIT 5");
	$productCount = mysql_num_rows($sql); // count the output amount
	
		if ($productCount > 0) {

			while($row = mysql_fetch_array($sql)){ 
	             	$id = $row["id"];
				 	$product_name = $row["product_name"];
				 	$price = $row["price"];
				 	$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
				 	$dynamicList .= '<table border="0" cellspacing="5" cellpadding="0">
				 <tr>
	          	<td rowspan="3"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="50" height="65" border="1" /></a></td>
				<td>' . $product_name . '<br />
				$' . $price . '<br />
	  			<a href="product.php?id=' . $id . '">View Product Details</a>
				</td>
				</tr>
	      		</table>';
    		}//end of while loop
			echo $dynamicList;
		} else {
			$dynamicList = "We have no products listed in our store yet";
			mysql_close();
		}//end of nested if statement		
	
}

function print_list() {
require("config.php");
	
	$category = $_GET['cat']; //get category type
	$subcategory = $_GET['subcat']; //get subcategory type

if ($category == NULL && $subcategory == NULL) {
	
	$dynamicList = "";
	$list = "";
	$sql = mysql_query("SELECT * FROM products ORDER BY date_added");
	$productCount = mysql_num_rows($sql); // count the output amount
		$list .='<h2> Luvo Fashion Collection </h2><br><ul id="slider-one">';
		echo $list;
		if ($productCount > 0) {
			while($row = mysql_fetch_array($sql)){ 
	             	$id = $row["id"];
				 	$product_name = $row["product_name"];
				 	$price = $row["price"];
				 	$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
				 	$dynamicList .= '<li style="border-right:none; width:200px;">
				<a href="product.php?id=' . $id . '"><img src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="150" height="200" border="0" />
				<h2>'.$product_name.'</h2><h2>'.$price.'</h2></li>';
    		}//end of while loop
			echo $dynamicList;
			$list2 .= '</ul>';
			echo $list2;
		} else {
			$dynamicList = "We have no products listed in our store yet";
			mysql_close();
		}//end of nested if statement		

} else {
							
	$dynamicList = "";
	$sql = mysql_query("SELECT * FROM products WHERE category = '$category' AND subcategory = '$subcategory' ORDER BY date_added");
	$productCount = mysql_num_rows($sql); // count the output amount
	$list = '<div align="right"><a href="gallery.php">Back to Main Gallery</a></div>';
	echo $list;					
		if ($productCount > 0) {			
			while($row = mysql_fetch_array($sql)){ 
				$id = $row["id"];
				$product_name = $row["product_name"];
				$price = $row["price"];
				$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
				$dynamicList .= '
				<table width="100%" border="0" cellspacing="5" cellpadding="6">
				<tr>
	          	<td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="98" height="145" border="1" /></a></td>
	          	<td width="83%" valign="top">' . $product_name . '<br />
	            	$' . $price . '<br />
	            	<a href="product.php?id=' . $id . '">View Product Details</a></td>
					</td>
	      		</table>';	
    		}//end of while looop
			echo $dynamicList;
		} else {
			$dynamicList = "We have no products listed in our store yet";
			mysql_close();
		}//end of nested if statement
}

}//end of function
mysql_close();

function print_images(){
	require("config.php");
	
	$dynamicList = "";
	$sql = mysql_query("SELECT * FROM products ");
	$productCount = mysql_num_rows($sql); // count the output amount
	
		if ($productCount > 0) {

			while($row = mysql_fetch_array($sql)){ 
	             	$id = $row["id"];
				 	$product_name = $row["product_name"];
				 	$dynamicList .= '<li><a href="product.php?id=' . $id . '"><img src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="70" height="85" border="0" /></li>';
    		}//end of while loop
			echo $dynamicList;
		} else {
			$dynamicList = "We have no products listed in our store yet";
			mysql_close();
		}//end of nested if statement
}